package com.zsc.graduate.qovipan.config;

import org.apache.catalina.ssi.SSIServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 枫树下奶罐
 * @version 1.0.0
 * @date 2021/11/26 23:45
 */
@Configuration
@Controller
public class MainConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/register").setViewName("register");
        registry.addViewController("/head-navi").setViewName("head-navi");
        registry.addViewController("/footer").setViewName("footer");
        registry.addViewController("/update").setViewName("update");
        registry.addViewController("/download").setViewName("download");
        registry.addViewController("/about").setViewName("about");
        registry.addViewController("/media-player").setViewName("media-player");
        registry.addViewController("/*.html");
        registry.addViewController("/*.shtml");
    }
//    @RequestMapping("/footer")
//    public String footer(Map<String,Object> map){
//        List<User> users = userMapper.selectList(null);
//        log.info("------>footer.html----->"+new Date());
//        return "footer";
//    }
//
//    //开启SSI服务，相当于 conf/web.xml 配置
//    @Bean
//    public ServletRegistrationBean servletRegistrationBean() {
//        ServletRegistrationBean servlet = new ServletRegistrationBean();
//        servlet.setServlet(new SSIServlet());
//        List<String> urlMapping = new ArrayList<>(1);
//        urlMapping.add("*.shtml");
//        servlet.setUrlMappings(urlMapping);
//        servlet.addInitParameter("outputEncoding", "UTF-8");
//        servlet.addInitParameter("inputEncoding", "UTF-8");
//        return servlet;
//    }
}
